#!/bin/bash

action="${1}"
branch="${2}"

for name in mozdef_cognito_proxy mozdef_meteor mozdef_base mozdef_tester mozdef_mq_worker mozdef_kibana \
        mozdef_syslog mozdef_cron mozdef_elasticsearch mozdef_loginput mozdef_mongodb \
        mozdef_bootstrap mozdef_alerts mozdef_nginx mozdef_alertactions mozdef_rabbitmq \
        mozdef_rest mozdef_base ; do
    if [ "${action}" == "tag" ]; then
        echo "Tagging local image mozdef/${name}:latest as mozdef/${name}:${branch}"
        docker tag mozdef/${name}:latest mozdef/${name}:${branch}
    elif [ "${action}" == "push" ]; then
        echo "Pushing local image mozdef/${name}:${branch} to DockerHub"
        docker push mozdef/${name}:${branch}
        if [ "${branch}" == "master" ]; then
            echo "Pushing local image mozdef/${name}:latest to DockerHub"
            docker push mozdef/${name}:latest
        fi
    fi
done
